import PyPDF2

# 提取PDF文件的指定界面
# 使用实例：extract_pages('input.pdf', 'output.pdf', [0, 2, 4])
def extract_pages(pdf_path, output_path, page_indices):
    with open(pdf_path, 'rb') as file:
        pdf_reader = PyPDF2.PdfReader(file)
        pfd_writer = PyPDF2.PdfWriter()
    
        for page_num in page_indices:
            page = pdf_reader.pages[page_num]
            pfd_writer.add_page(page)

        with open(output_path, 'wb') as output_file:
            pfd_writer.write(output_file)
